import { createSlice, PayloadAction } from '@reduxjs/toolkit';

const namespace = 'user';

export interface GlobalState {
  /**
   * 头像地址
   */
  src?: string | undefined | null;
  /**
   * 建议列数
   */
  size: 'small';
  /**
   * 用户名
   */
  title?: string;
}

const initialState: GlobalState = {
  size: 'small',
  title: '默认用户',
};
const globalSlice = createSlice({
  name: namespace,
  initialState,
  reducers: {
    setUser: (state, action: PayloadAction<GlobalState>) => {
      const { src, size, title } = action.payload;
      if (src != state.src) {
        state.src = src;
      }
      if (title != state.title) {
        state.title = title;
      }
    },
  },
  extraReducers: () => {},
});

export const { setUser } = globalSlice.actions;

export default globalSlice.reducer;
